﻿using UnityEngine;
using System.Collections;

public class background : MonoBehaviour {


    public float dampTime = 0.15f;
    private Vector3 velocity = Vector3.zero;
    public Transform target;
    public float vertical_speed;
    public float horizontal_speed;

    private Vector3 pos;
    private Vector3 startPos;
    private Vector3 startTargetPos;

	// Use this for initialization
	void Start () {
        startPos = transform.position;
        startTargetPos = target.position;
	}
	
	// Update is called once per frame
    void Update()
    {   
        
        if (target)
        {
            //transform.position = target.position;
            pos = startPos;
            pos.x += horizontal_speed * (target.position.x - startTargetPos.x);
            pos.y += vertical_speed * (target.position.y - startTargetPos.y); 
            pos.z += 20;

            transform.position = pos;
            //transform.TransformVector(0, 0, 20);
            //Debug.Log(" " + transform.position.x + " " + transform.position.y + " " + transform.position.z);
            //Vector3 point = camera.WorldToViewportPoint(target.position);
            //Vector3 delta = target.position - camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, point.z)); //(new Vector3(0.5, 0.5, point.z));
            //Vector3 destination = transform.position + delta;
            //transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime);
        }
	
	}
}
